<?php

require_once dirname(__FILE__).'/../lib/greskaGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/greskaGeneratorHelper.class.php';

/**
 * greska actions.
 *
 * @package    dnevnik
 * @subpackage greska
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class greskaActions extends autoGreskaActions
{
   public function executePregled(sfWebRequest $request)
   {
      $br_po_strani = 20;
      if(($strana = $request->getParameter('strana')) > 1)
        $pocetak = ($strana - 1) * $br_po_strani;
      else $pocetak = 0;
      $greskas = DbFinder::from('Greska')->join('Profil')->with('Profil')->orderBy('Status')->orderBy('CreatedAt', 'desc')->offset($pocetak)->limit($br_po_strani)->find();
      $broj = DbFinder::from('Greska')->join('Profil')->count() / $br_po_strani;

      $this->greskas = $greskas;
      $this->broj = $broj;
   }

   public function executeDetail(sfWebRequest $request)
   {
      $greska = DbFinder::from('Greska')->findPk($request->getParameter('id'));
      if(!$greska->getStatus())
      {
         $greska->setStatus(GreskaPeer::$status['procitan']);
         $greska->save();
      }

      $this->greska = $greska;
   }

   public function executeOdgovori(sfWebRequest $request)
   {
      $greska = DbFinder::from('Greska')->findPk($request->getParameter('id'));
      if($request->getParameter('status'))
         $greska->setStatus(GreskaPeer::$status['resen']);
      else $greska->setStatus(GreskaPeer::$status['procitan']);
      $greska->setOdgovor($request->getParameter('odgovor'));
      $greska->setOdgovorAt(date("Y-m-d H:i:s"));

      $greska->save();

      return $this->renderText('Odgovoreno');
   }
}
